<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>props 限制属性的值</title>
</head>
<body>
    <div id="root"> </div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>
    <!-- 1. 引入 js 文件 -->
    <script src="../js/prop-types.js"></script>
    <script type="text/babel">
        //学员的类式组件
        class Student extends React.Component{

            //2. 声明一个静态属性
            static propTypes = {
                age: PropTypes.number, //限制传入的 age 属性值为『数字』,
                name: PropTypes.string.isRequired, //限制传入的 name 的属性值为『字符串』
                gender: PropTypes.string.isRequired, 
            }

            //默认的属性值
            static defaultProps = {
                gender: '保密'
            }

            render(){
                let {age, name, gender} = this.props;
                //接收外部传入到组件内的数据
                return <ul>
                        <li>姓名: {name}</li>
                        <li>年龄:  {age}</li>
                        <li>性别:  {gender}</li>
                    </ul>
            }
        }


        ReactDOM.render(<Student age={16} name="智浩"  />, document.querySelector("#root"));
    </script>
</body>
</html>